

#import "FAMGenderViewController.h"

@interface FAMGenderViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *FAMPageBackView;
@property (weak, nonatomic) IBOutlet UIButton *FAMMaleButton;
@property (weak, nonatomic) IBOutlet UIButton *FAMFemaleButton;
@property (nonatomic, strong)NSMutableDictionary *FAMFoodmateUserdataDictionary;
@property (weak, nonatomic) IBOutlet UITextView *FAMPrivacyTextView;
@property (weak, nonatomic) IBOutlet UIScrollView *FAMScrollView;

@end

@implementation FAMGenderViewController
- (NSMutableDictionary *)FAMFoodmateUserdataDictionary{
    if (!_FAMFoodmateUserdataDictionary) {
        _FAMFoodmateUserdataDictionary = [NSMutableDictionary dictionary];
    }
    return _FAMFoodmateUserdataDictionary;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self FAM_showUi];
    self.fd_prefersNavigationBarHidden = YES;
}
- (void)FAM_showUi{
    self.FAMScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.FAMPageBackView.layer.shadowColor = kCustom0xColor(0x000000, 1.0).CGColor;
    self.FAMPageBackView.layer.shadowOpacity = 0.15;
    self.FAMPageBackView.layer.shadowRadius = 1.5;
    self.FAMPageBackView.layer.shadowOffset = CGSizeMake(2, 2);
    self.FAMFemaleButton.layer.borderColor = kBlackColor.CGColor;
    self.FAMFemaleButton.layer.borderWidth = 2;
    [self.FAMFoodmateUserdataDictionary setValue:@"2" forKey:@"gender"];
    self.FAMPrivacyTextView.delegate = self;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithAttributedString:self.FAMPrivacyTextView.attributedText];
    [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(attributedString.length - 15, 15)];
    [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(attributedString.length - 30, 12)];
    [attributedString addAttribute:NSLinkAttributeName
                                 value:@"yonghu://"
                                 range:[[attributedString string] rangeOfString:@"Terms of Use"]];
    [attributedString addAttribute:NSLinkAttributeName
                             value:@"yinsi://"
                             range:[[attributedString string] rangeOfString:@"Privacy Policy"]];
    self.FAMPrivacyTextView.attributedText = attributedString;
    self.FAMPrivacyTextView.textAlignment = NSTextAlignmentCenter;
    self.FAMPrivacyTextView.editable = NO;
    self.FAMPrivacyTextView.scrollEnabled = NO;
//    self.FAMPrivacyTextView.linkTextAttributes = @{
//        NSForegroundColorAttributeName: kCustom0xColor(0x4CA668, 1.0),
//        NSUnderlineColorAttributeName: kCustom0xColor(0x232323,1.0),
//        NSUnderlineStyleAttributeName: @(NSUnderlinePatternSolid),
//        NSFontAttributeName:[UIFont systemFontOfSize:13]
//    };
}

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
    if ([[URL scheme] isEqualToString:@"yonghu"]) {
        FAMMinePrivacyViewController *vc = [[FAMMinePrivacyViewController alloc]init];
        vc.FAMIsPrivacy = NO;
        [self.navigationController pushViewController:vc animated:YES];
        return NO;
    } else if ([[URL scheme] isEqualToString:@"yinsi"]) {
        FAMMinePrivacyViewController *vc = [[FAMMinePrivacyViewController alloc]init];
        vc.FAMIsPrivacy = YES;
        [self.navigationController pushViewController:vc animated:YES];
        return NO;
    }
    return YES;
}
- (IBAction)FAM_nextButtonClick:(UIButton *)sender {
    FAMAgeViewController *vc = [FAMAgeViewController new];
    vc.FAMFoodmateUserdataDictionary = self.FAMFoodmateUserdataDictionary;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)FAM_maleButtonClick:(UIButton *)sender {
    [self.FAMFemaleButton setSelected:NO];
    [sender setSelected:YES];
    sender.layer.borderColor = kBlackColor.CGColor;
    sender.layer.borderWidth = 2;
    self.FAMFemaleButton.layer.borderColor = kClearColor.CGColor;
    self.FAMFemaleButton.layer.borderWidth = 2;
    self.FAMFoodmateUserdataDictionary[@"gender"] = @"1";
}
- (IBAction)FAM_femaleButtonClick:(UIButton *)sender {
    [sender setSelected:YES];
    [self.FAMMaleButton setSelected:NO];
    sender.layer.borderColor = kBlackColor.CGColor;
    sender.layer.borderWidth = 2;
    self.FAMMaleButton.layer.borderColor = kClearColor.CGColor;
    self.FAMMaleButton.layer.borderWidth = 2;
    self.FAMFoodmateUserdataDictionary[@"gender"] = @"2";
}

- (IBAction)FAM_privacyTapClick:(UITapGestureRecognizer *)sender {
    FAMMinePrivacyViewController *vc = [[FAMMinePrivacyViewController alloc]init];
    vc.FAMIsPrivacy = YES;
    [self.navigationController pushViewController:vc animated:YES];
}




@end
